<template>
  <div class="container">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="60px" class="demo-ruleForm">
      <el-form-item label="帐号" prop="userPhone">
        <el-input v-model="ruleForm.userPhone"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="passWord">
        <el-input type="password" v-model="ruleForm.passWord"></el-input>
      </el-form-item>
      <el-form-item class="noMargin">
        <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'login',
  data () {
    return {
      ruleForm: {
        userPhone: '',
        passWord: ''
      },
      rules: {
        userPhone: [
          { required: true, message: '请输入帐号', trigger: 'blur' },
          { min: 5, max: 18, message: '长度在 5 到 18 个字符', trigger: 'blur' }
        ],
        passWord: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 5, max: 18, message: '长度在 5 到 18 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$cookie.set('token', '123456')
          this.$router.push({path: '/'})
          this.$message({
            type: 'success',
            message: '登陆成功！'
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
  .container{
    width:300px;
    border-radius:10px;
    box-shadow: 0 0 15px 5px rgba(0,0,0,0.3);
    margin:30vh  auto 10vh;
    padding:80px;

    /deep/ .noMargin .el-form-item__content{
      margin-left:0 !important;
      button{
        width:100%;
        margin:30px auto 0;
      }
    }
  }

</style>
